package GUI;
/**
 * Select a student for exceptional request to remove a student from a course 
 * during the semester
 */
import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import Common.StudentClass;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SelectStudentForEx extends JPanel {
	
	private JComboBox cBSelStudent = null;
	private JLabel lblSelectStudent = null;
	private JButton btnNext=null;
	
	public String selectedStudent=null;
	public Login myLoginFrame = null;
	public UserAdmin user=null;
	public AdminMainMenu amn=null;
	private StudentRemovalFromCourse studentRmvFrmCrsScreen=null;
	private Vector<String> data=null;
	
	
	
	public SelectStudentForEx(AdminMainMenu amn) {
		super();
		initialize(amn);
			
	}
	
	
	public JButton getNextButton()
	{
		if(btnNext==null)
		{
			btnNext = new JButton("Next");
			btnNext.setBounds(324, 230, 89, 23);
			btnNext.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					user.SetName(selectedStudent);
					studentRmvFrmCrsScreen=null;
					studentRmvFrmCrsScreen=amn.getstudentRmvFrmCrsScreen();
					amn.setContentPane(studentRmvFrmCrsScreen);
				
				//pmn.pViewPD.myLoginFrame=pmn.myLoginFrame;
					
				}
			});
			
		}
		
		return btnNext;
			
	}
	private void initialize(AdminMainMenu amn)
	{
		setLayout(null);
		lblSelectStudent = new JLabel("Select Student:");
		lblSelectStudent.setBounds(45, 84, 74, 14);
		
		add(lblSelectStudent);
		add(getSelStudentCb(amn));
		add(getNextButton());
		
	}
	
	
	
	public JComboBox getSelStudentCb(AdminMainMenu amn)
	{
		
		data = new Vector<String>();
		for(int i=0;i<amn.user.DataForEx.StudentsWithCourses.size();i++)
		{
			
			System.out.println("test1" + amn.user.DataForEx.StudentsWithCourses.get(i).ClassId );
			System.out.println("test2" + amn.user.GetClass() );
			//TODO handle the null situation
			if((amn.user.DataForEx.StudentsWithCourses.get(i).ClassId!=null)&&(amn.user.DataForEx.StudentsWithCourses.get(i).ClassId.equalsIgnoreCase(amn.user.GetClass()))&&
					(amn.user.DataForEx.StudentsWithCourses.get(i).ListOfCourses.lOfCourses!=null))
			{
				
			data.add(amn.user.DataForEx.StudentsWithCourses.get(i).FirstName +" "+amn.user.DataForEx.StudentsWithCourses.get(i).LastName +" "+amn.user.DataForEx.StudentsWithCourses.get(i).Sid);
			}
			
		}
		
		cBSelStudent  = new JComboBox(data);
		cBSelStudent.setBounds(139, 81, 243, 20);
		//cBSelStudent.insertItemAt("Select Student", 1);
		cBSelStudent.addActionListener(new java.awt.event.ActionListener() {
	
		public void actionPerformed(java.awt.event.ActionEvent e) {
		selectedStudent= cBSelStudent.getSelectedItem().toString();
		
		System.out.println(selectedStudent);
		 
		
		
		 	}
		
	
		});

		return cBSelStudent;
	}
}
